classdef Export < preparser.control.BaseClass
    properties
        FileName
        Body
    end
    
    
    
    
    methods
        function this = Export(varargin)
            if isempty(varargin)
                return
            end
            c = varargin{1};
            sh = varargin{2};
            construct(this, c, sh);
        end
        
        
        
        
        function c = writeFinal(this, p, varargin)
            import preparser.control.Control;
            c = '';
            fileName = this.FileName;
            if ~isempty(p.StoreForCtrl) && ~isempty(strfind(fileName, '?'))
                fileName = Control.substituteForCtrl(fileName, p);
            end
            fileName = strtrim(fileName);            
            fileContents = writeFinal(this.Body, p, varargin{:});
            fileContents = textfun.removeltel(fileContents);
            addExportable(p, fileName, fileContents);
        end
        
        
        
        
        function construct(this, c, sh)
            import preparser.control.*;
            c0 = c;
            key = Keyword.EXPORT;
            [fileName, c, sh] = Export.getBracketArg(key, c, sh);
            if isempty(fileName)
                error('IRIS:Preparser:Controls:MissingExportFileName', c0);
            end
            this.FileName = fileName;
            this.Body = Control(c, [ ], sh);
        end        
    end
    
    
end
